﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;

namespace ProdStatistics
{
    public static class Visualiser
    {
        public static void DrawPermissionsGUI(User user, PSForm form)
        {
            foreach (Permission p in user.Role.Permissions)
            {
                switch (p.Type)
                {
                    case PermissionType.EditUsers: form.MainMenuStrip.Items[0].Enabled = true; break;
                    case PermissionType.EditCosts: form.MainMenuStrip.Items[1].Enabled = true; break;                    
                    case PermissionType.GenerateReports: form.MainMenuStrip.Items[2].Enabled = true; break;
                }
            }
        }

        public static void DrawDiagramm(DiagramType type, DataTable report_data, Chart chart)
        {
            if (type == DiagramType.Sector)
            {
                chart.Legends[0].Enabled = true;
                chart.Series[0].IsValueShownAsLabel = true;

                string strvalue1 = report_data.Rows[0].ItemArray[0].ToString();
                string strvalue2 = report_data.Rows[0].ItemArray[1].ToString();

                double value1 = double.Parse(strvalue1.Substring(0, strvalue1.LastIndexOf(",") + 5));
                double value2 = double.Parse(strvalue2.Substring(0, strvalue2.LastIndexOf(",") + 5));

                chart.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                chart.Series[0].Points.AddXY(report_data.Columns[0].ColumnName, value1);
                chart.Series[0].Points.AddXY(report_data.Columns[1].ColumnName, value2);                        
            }
            else if (type == DiagramType.Graphic)
            {
                string[] masX = new string[report_data.Rows.Count];
                double[] masY = new double[report_data.Rows.Count];

                for (int i = 0; i < report_data.Rows.Count; i++)
                {
                    masX[i] = report_data.Rows[i][0].ToString();
                }

                for (int i = 0; i < report_data.Rows.Count; i++)
                {
                    string value = report_data.Rows[i][1].ToString();
                    masY[i] = double.Parse(value.Substring(0,value.LastIndexOf(",")+5));
                }

                chart.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                for (int i = 0; i < report_data.Rows.Count; i++)
                {
                    chart.Series[0].Points.AddXY(masX[i], masY[i]);
                }

                chart.Series[0].MarkerStyle = MarkerStyle.Circle;
                chart.Legends[0].Enabled = false;
                chart.Series[0].IsValueShownAsLabel = true;
              
                chart.Series[0].MarkerColor = Color.DarkBlue;
                chart.Series[0].MarkerSize = 8;
                chart.ChartAreas[0].AxisX.TitleFont = new Font("Microsoft Sans Serif",11);
                chart.ChartAreas[0].AxisY.TitleFont = new Font("Microsoft Sans Serif", 11);
                chart.ChartAreas[0].AxisX.Title = report_data.Columns[0].ColumnName;
                chart.ChartAreas[0].AxisY.Title = report_data.Columns[1].ColumnName;
            }
        }

       
    }
}
